package cn.org.tpeach.nosql.controller;

import cn.org.tpeach.nosql.framework.LarkFrame;
import cn.org.tpeach.nosql.view.JavaFxUtil;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import lombok.NoArgsConstructor;


@NoArgsConstructor
public class RedisApplication extends Application {

    public static MainController mainController;

    public RedisApplication(String[] args) {
		launch(args);
	}


	@Override
    public void start(Stage primaryStage) {
        LarkFrame.primaryStage = primaryStage;
        try {
            FXMLLoader fxmlLoader = new FXMLLoader();
            Parent page =  JavaFxUtil.loadFxml(fxmlLoader, "/view/fxml/main.fxml");
            mainController = fxmlLoader.getController();
            Scene scene = new Scene(page,1350,730);
            scene.getStylesheets().add("/view/css/default.css");
//            scene.getStylesheets().add("/view/css/blackTheme.css");
            scene.getStylesheets().add("/view/css/common.css");
            primaryStage.setTitle("Redis Lettuce Client");
            primaryStage.getIcons().add(new Image(RedisApplication.class.getResourceAsStream("/view/img/lettuce.png")));
            primaryStage.setOnCloseRequest(JavaFxUtil::exit);
            primaryStage.maximizedProperty().addListener((observable, oldValue, newValue) -> {

            });
            primaryStage.widthProperty().addListener((observable, oldValue, newValue) -> {
                double width = mainController.getLeftDbInfoPane().getWidth();
                SplitPane treeAndDataSplitPane = mainController.getTreeAndDataSplitPane();
//                controller.getTreeAndDataSplitPane().setDividerPositions(width/newValue.doubleValue());

            });

            primaryStage.setScene(scene);
            primaryStage.show();

//            redisConfigService.addRedisConfig(source);
//            redisConfigService.updateRedisConfig(source);
//            redisConfigService.deleteRedisConfigById("fda3e3d185874fb389150c663b2b9d3e");
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

}
